/*
 * Powered By [rapid-framework]
 * Web Site: http://www.rapid-framework.org.cn
 * Google Code: http://code.google.com/p/rapid-framework/
 * Since 2008 - 2011
 */

package com.tech15.core.model;

import java.util.List;

import javacommon.base.BaseEntity;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.validation.constraints.Max;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.validator.constraints.Length;

import cn.org.rapid_framework.util.DateConvertUtils;

/**
 * @author 胡作正 email:zuozhenghu@sina.com
 * @version 1.0
 * @since 1.0
 */


@Entity
@Table(name = "SYS_USER")
public class SysUser extends BaseEntity implements java.io.Serializable{
	private static final long serialVersionUID = 5454155825314635342L;
	
	//alias
	public static final String TABLE_ALIAS = "用户";
	public static final String ALIAS_USERID = "用户id";
	public static final String ALIAS_USERNAME = "用户名";
	public static final String ALIAS_REALNAME = "真实姓名";
	public static final String ALIAS_PASSWORD = "登录密码";
	public static final String ALIAS_MEMO = "备注";
	public static final String ALIAS_STATE = "状态";
	public static final String ALIAS_EMAIL = "email";
	public static final String ALIAS_LASTLOGINIP = "最后登录ip";
	public static final String ALIAS_LASTLOGINTIME = "最后登录时间";
	public static final String ALIAS_CATEGORY = "客户类型(1 客户 0 用户)";
	public static final String ALIAS_LOGINCOUNT = "登录次数";
	
	//date formats
	public static final String FORMAT_LASTLOGINTIME = DATE_TIME_FORMAT;
	

	//可以直接使用: @Length(max=50,message="用户名长度不能大于50")显示错误消息
	//columns START
	/**
     * 用户id       db_column: USERID 
     */ 	
	
	private Long userid;
    /**
     * 用户名       db_column: USERNAME 
     */ 	
	@Length(max=30)
	private java.lang.String username;
    /**
     * 真实姓名       db_column: REALNAME 
     */ 	
	@Length(max=20)
	private java.lang.String realname;
    /**
     * 登录密码       db_column: PASSWORD 
     */ 	
	@Length(max=32)
	private java.lang.String password;
    /**
     * 备注       db_column: MEMO 
     */ 	
	@Length(max=100)
	private java.lang.String memo;
    /**
     * 状态       db_column: STATE 
     */ 	
	@Length(max=1)
	private java.lang.String state;
    /**
     * email       db_column: EMAIL 
     */ 	
	@Length(max=30)
	private java.lang.String email;
    /**
     * 最后登录ip       db_column: LASTLOGINIP 
     */ 	
	@Length(max=15)
	private java.lang.String lastloginip;
    /**
     * 最后登录时间       db_column: LASTLOGINTIME 
     */ 	
	
	private java.util.Date lastlogintime;
	/**
     * 客户类型       db_column: ISADMIN 
     */ 	
	@Max(127)
	private Integer isadmin;
	/**
     * 登录次数       db_column: LOGINCOUNT 
     */ 	
	private Long logincount;
	/**
     * 部门id       db_column: DEPTID 
     */ 	
	private Long deptid;
	
	/**
     * 类型       db_column: CATEGORY 
     */ 	
	@Max(127)
	private Integer category;
	/**
     * 部门       db_column: DEPTNAME 
     */ 	
	private String deptname;
	/**
     * 用户角色       db_column: USERROLE 
     */ 	
	@Max(127)
	private Integer userrole;
	/**
     * 任务部门       db_column: TASKDEPTID 
     */ 	
	
	private Long taskdeptid;
	//columns END


	public SysUser(){
	}

	public SysUser(
		Long userid
	){
		this.userid = userid;
	}

	

	public void setUserid(Long value) {
		this.userid = value;
	}
	
	@Id @GeneratedValue(generator="custom-id")
	@GenericGenerator(name="custom-id", strategy = "increment")
	@Column(name = "USERID", unique = true, nullable = false, insertable = true, updatable = true, length = 22)
	public Long getUserid() {
		return this.userid;
	}
	
	@Column(name = "USERNAME", unique = true, nullable = true, insertable = true, updatable = true, length = 30)
	public java.lang.String getUsername() {
		return this.username;
	}
	
	public void setUsername(java.lang.String value) {
		this.username = value;
	}
	
	@Column(name = "REALNAME", unique = false, nullable = true, insertable = true, updatable = true, length = 20)
	public java.lang.String getRealname() {
		return this.realname;
	}
	
	public void setRealname(java.lang.String value) {
		this.realname = value;
	}
	
	@Column(name = "PASSWORD", unique = false, nullable = true, insertable = true, updatable = true, length = 32)
	public java.lang.String getPassword() {
		return this.password;
	}
	
	public void setPassword(java.lang.String value) {
		this.password = value;
	}
	
	@Column(name = "MEMO", unique = false, nullable = true, insertable = true, updatable = true, length = 100)
	public java.lang.String getMemo() {
		return this.memo;
	}
	
	public void setMemo(java.lang.String value) {
		this.memo = value;
	}
	
	@Column(name = "STATE", unique = false, nullable = true, insertable = true, updatable = true, length = 1)
	public java.lang.String getState() {
		return this.state;
	}
	
	public void setState(java.lang.String value) {
		this.state = value;
	}
	
	
	@Column(name = "EMAIL", unique = false, nullable = true, insertable = true, updatable = true, length = 30)
	public java.lang.String getEmail() {
		return this.email;
	}
	
	public void setEmail(java.lang.String value) {
		this.email = value;
	}
	
	@Column(name = "LASTLOGINIP", unique = false, nullable = true, insertable = true, updatable = true, length = 15)
	public java.lang.String getLastloginip() {
		return this.lastloginip;
	}
	
	public void setLastloginip(java.lang.String value) {
		this.lastloginip = value;
	}
	
	@Transient
	public String getLastlogintimeString() {
		return DateConvertUtils.format(getLastlogintime(), FORMAT_LASTLOGINTIME);
	}
	public void setLastlogintimeString(String value) {
		setLastlogintime(DateConvertUtils.parse(value, FORMAT_LASTLOGINTIME,java.util.Date.class));
	}
	
	@Column(name = "LASTLOGINTIME", unique = false, nullable = true, insertable = true, updatable = true, length = 7)
	public java.util.Date getLastlogintime() {
		return this.lastlogintime;
	}
	
	public void setLastlogintime(java.util.Date value) {
		this.lastlogintime = value;
	}
	
	@Column(name = "ISADMIN", unique = false, nullable = true, insertable = true, updatable = true, length = 2)
	public Integer getIsadmin() {
		return this.isadmin;
	}
	
	public void setIsadmin(Integer value) {
		this.isadmin = value;
	}
	
	@Column(name = "LOGINCOUNT", unique = false, nullable = true, insertable = true, updatable = true, length = 22)
	public Long getLogincount() {
		return this.logincount;
	}
	
	public void setLogincount(Long value) {
		this.logincount = value;
	}
	
	@Column(name = "DEPTID", unique = false, nullable = true, insertable = true, updatable = true, length = 22)
	public Long getDeptid() {
		return this.deptid;
	}
	
	public void setDeptid(Long value) {
		this.deptid = value;
	}
	
	@Column(name = "CATEGORY", unique = false, nullable = true, insertable = true, updatable = true, length = 2)
	public Integer getCategory() {
		return this.category;
	}
	
	public void setCategory(Integer value) {
		this.category = value;
	}
	
	@Column(name = "DEPTNAME", unique = false, nullable = true, insertable = true, updatable = true, length = 30)
	public String getDeptname() {
		return this.deptname;
	}
	
	public void setDeptname(String value) {
		this.deptname = value;
	}
	
	@Column(name = "USERROLE", unique = false, nullable = true, insertable = true, updatable = true, length = 2)
	public Integer getUserrole() {
		return this.userrole;
	}
	
	public void setUserrole(Integer value) {
		this.userrole = value;
	}
	
	@Column(name = "TASKDEPTID", unique = false, nullable = true, insertable = true, updatable = true, length = 22)
	public Long getTaskdeptid() {
		return this.taskdeptid;
	}
	
	public void setTaskdeptid(Long value) {
		this.taskdeptid = value;
	}
	
	
	/*private SysDept sysDept;
	public void setSysDept(SysDept sysDept){
		this.sysDept = sysDept;
	}
	
	@ManyToOne(cascade = {}, fetch = FetchType.LAZY)
	@JoinColumns({
		@JoinColumn(name = "DEPTID",nullable = false, insertable = false, updatable = false) 
	})
	public SysDept getSysDept() {
		return sysDept;
	}*/

	public String toString() {
		return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
			.append("Username",getUsername())
			.append("Realname",getRealname())
			.append("Password",getPassword())
			.append("Memo",getMemo())
			.append("State",getState())
			.append("Email",getEmail())
			.append("Lastloginip",getLastloginip())
			.append("Lastlogintime",getLastlogintime())
			.toString();
	}
	
	public int hashCode() {
		return new HashCodeBuilder()
			.append(getUsername())
			.toHashCode();
	}
	
	public boolean equals(Object obj) {
		if(obj instanceof SysUser == false) return false;
		if(this == obj) return true;
		SysUser other = (SysUser)obj;
		return new EqualsBuilder()
			.append(getUsername(),other.getUsername())
			.isEquals();
	}
	
	private Long pgid;
	private java.lang.String groupIds;
	private List<Group> groupList;
	private String pwd;
	private Long id;
	private String name;
	private String orgInfo;
	private String deptName;
	private String zw;
	
	private String tel;
	private String phone;
	private String taskdeptname;
	
	@Transient
	public String getTaskdeptname() {
		return taskdeptname;
	}

	public void setTaskdeptname(String taskdeptname) {
		this.taskdeptname = taskdeptname;
	}

	@Transient
	public String getPhone() {
		return phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}

	@Transient
	public String getTel() {
		return tel;
	}

	public void setTel(String tel) {
		this.tel = tel;
	}

	@Transient
	public String getZw() {
		return zw;
	}

	public void setZw(String zw) {
		this.zw = zw;
	}

	@Transient
	public String getDeptName() {
		return deptName;
	}

	public void setDeptName(String deptName) {
		this.deptName = deptName;
	}

	@Transient
	public String getOrgInfo() {
		return orgInfo;
	}

	public void setOrgInfo(String orgInfo) {
		this.orgInfo = orgInfo;
	}

	@Transient
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	@Transient
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Transient
	public String getPwd() {
		return pwd;
	}

	public void setPwd(String pwd) {
		this.pwd = pwd;
	}

	@Transient
	public List<Group> getGroupList() {
		return groupList;
	}

	public void setGroupList(List<Group> groupList) {
		this.groupList = groupList;
	}
	@Transient
	public java.lang.String getGroupIds() {
		return this.groupIds;
	}
	
	public void setGroupIds(java.lang.String value) {
		this.groupIds = value;
	}
	@Transient
	public Long getPgid() {
		return pgid;
	}

	public void setPgid(Long pgid) {
		this.pgid = pgid;
	}
	
}

